import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;
import helpers.*;

public class ASTWalker {
	public static final int XML_PARSER = 0;
    public static final int C_PARSER = 1;
	
	static final TreeAdaptor adaptor = new CommonTreeAdaptor() {
		public Object create(Token payload) {
			return new Arbolito(payload);
		}
	};
	
	public static void main(String[] args) {
		try {
            //switch (Integer.parseInt(args[0])) {
			switch (C_PARSER) {
            case XML_PARSER:
            	XMLexer xmlexer = new XMLexer(new ANTLRFileStream("test/in1.xml"));
                CommonTokenStream xmltokens = new CommonTokenStream(xmlexer);
                XMLParser xmlparser = new XMLParser(xmltokens);
                xmlparser.setTreeAdaptor(adaptor);
                XMLParser.xmldocument_return xmlret = xmlparser.xmldocument();
                Arbolito xmltree = (Arbolito) xmlret.getTree();
                ASTFrame xmlaf = new ASTFrame("test/in1.xml", xmltree);
                xmlaf.setVisible(true);
            	break;
            case C_PARSER:
            	CLexer clexer = new CLexer(new ANTLRFileStream("test/prueba.c"));
                CommonTokenStream ctokens = new CommonTokenStream(clexer);
                CParser cparser = new CParser(ctokens);
                cparser.setTreeAdaptor(adaptor);
                CParser.entrada_return cret = cparser.entrada();
                Arbolito ctree = (Arbolito) cret.getTree();
                ASTFrame caf = new ASTFrame("test/prueba.c", ctree);
                caf.setVisible(true);
            	break;
            }
			/*CLexer clexer = new CLexer(new ANTLRFileStream("test/in1.c"));
            CommonTokenStream ctokens = new CommonTokenStream(clexer);
            CParser cparser = new CParser(ctokens);
            cparser.setTreeAdaptor(adaptor);
            CParser.entrada_return cret = cparser.entrada();
            Arbolito ctree = (Arbolito) cret.getTree();
            ASTFrame caf = new ASTFrame("test/in1.c", ctree);
            caf.setVisible(true);*/
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
